package com.image.fresco.zoomable;

import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

/**
 * Created by Bond on 2017/02/08 17:57
 * you can contact me at qbaowei@qq.com
 */


public abstract class BaseZoomablePagerAdapter<T> extends PagerAdapter {

    private List<T> mTs;

    public BaseZoomablePagerAdapter(List<T> ts) {
        mTs = ts;
    }

    @Override
    public int getCount() {
        return null == mTs ? 0 : mTs.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    public T getItem(int position) {
        if (position < 0 || position >= getCount()) {
            return null;
        }
        return mTs.get(position);
    }

    public void setTs(List<T> ts) {
        mTs = ts;
    }
}
